package com.dwy2002.room.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.dwy2002.enums.rabbit.DlxRabbitConstants.DLX_EXCHANGE;
import static com.dwy2002.enums.rabbit.DlxRabbitConstants.DLX_ROUTING_KEY;
import static com.dwy2002.enums.rabbit.TaskRabbitConstants.*;

/**
 * 任务Rabbit发送配置类
 *
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/07/15
 */
@Configuration
public class TaskRequestRabbitConfig {
    //对列声明
    @Bean
    public Queue taskRequestQueue() {
        return QueueBuilder.durable(TASK_TO_USER_REQUEST_QUEUE)
                .deadLetterExchange(DLX_EXCHANGE) // 绑定死信交换机
                .deadLetterRoutingKey(DLX_ROUTING_KEY)
                .build();
    }

    //交换机声明
    @Bean
    public DirectExchange taskRequestExchange() {
        return new DirectExchange(TASK_TO_USER_REQUEST_EXCHANGE);
    }

    //绑定声明
    @Bean
    public Binding taskRequestBinding() {
        return BindingBuilder.bind(taskRequestQueue())
                .to(taskRequestExchange())
                .with(TASK_TO_USER_REQUEST_ROUTING_KEY);
    }
}
